<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>The Warehouse</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'The Warehouse' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../intern.html">Inter Modules</a></li><li><a href="index.html">bytecode</a></li><li><a href="index.html#2">Chapter 2: The Trees</a></li><li><b>The Warehouse</b></li></ul></div>
<p class="purpose">To manage the memory storage of inter code.</p>

<ul class="toc"><li><a href="2-tw.html#SP1">&#167;1. Introduction</a></li><li><a href="2-tw.html#SP3">&#167;3. The resources</a></li><li><a href="2-tw.html#SP12">&#167;12. The bytecode storage</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Introduction.</b>The data structure in this section may bring to mind the title of the Metallica
song "The Thing That Should Not Be", but it works. It's also better than it used
to be (which is more than you can say for Metallica).
</p>

<p class="commentary">Each inter tree needs to store data outside of its own <a href="2-in.html#SP1" class="internal">inter_tree_node</a> structures,
data which falls into two categories:
</p>

<ul class="items"><li>&#9679; Bytecode for instructions, each having a unique address.
</li><li>&#9679; Resources such as texts and symbols tables, each having a unique ID number.
</li></ul>
<p class="commentary">This data is held in the <a href="2-tw.html#SP1" class="internal">inter_warehouse</a> connected to the tree. Each <a href="2-it.html#SP1" class="internal">inter_tree</a>
contains a pointer to its warehouse.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="comment-syntax"> bytecode storage</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">inter_warehouse_room</span><span class="plain-syntax"> *</span><span class="identifier-syntax">first_room</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">inter_warehouse_room</span><span class="plain-syntax"> *</span><span class="identifier-syntax">last_room</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="comment-syntax"> resource storage</span>
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">next_free_resource_ID</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">inter_warehouse_resource</span><span class="plain-syntax"> *</span><span class="identifier-syntax">stored_resources</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">resources_capacity</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure inter_warehouse is private to this section.</li></ul>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>An implementation secret, though, is that (in the present implementation, anyway)
there is only one warehouse. If there are multiple trees, they all share the use
of a single warehouse, though they don't know it. This would cause thread-safety
issues if Inter had any aspiration to be threaded, but it does not have. And this
single-warehouse design makes it much faster to carry out "transmigration" &mdash; the
movement of branches of Inter from one tree to another &mdash; since the associated
bytecode and resources do not need to be copied from one warehouse to another.
</p>

<p class="commentary">In this description we continue to talk about "a" warehouse, regardless of the
secret fact that there is only one.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">the_only_warehouse</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="function-syntax">InterWarehouse::new</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::new</span></span>:<br/>Inter Trees - <a href="2-it.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">the_only_warehouse</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax">);</span>

<span class="plain-syntax">        </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">first_room</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">last_room</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>

<span class="plain-syntax">        </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_free_resource_ID</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">stored_resources</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">resources_capacity</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="plain-syntax">        </span><span class="identifier-syntax">the_only_warehouse</span><span class="plain-syntax"> = </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">the_only_warehouse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. The resources.</b>The warehouse provides an array associating ID numbers with "resources": for
example, texts, or symbols tables. An ID is an unsigned integer with the lowest
legal ID being 1, so that 0 can safely be used to mean "no resource". Once
assigned, an ID is never reused.
</p>

<p class="commentary">Lookup needs tp be fast, so we store the list of resources as a flat array
which doubles in size each time its capacity is exceeded. This typically happens
about 10 times in a run of <a href="../inform7/index.html" class="internal">inform7</a>, for example, to hold on the order of
100,000 resources.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">inter_warehouse_resource</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">res</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">resource_owner</span><span class="plain-syntax">;</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">inter_warehouse_resource</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure inter_warehouse_resource is private to this section.</li></ul>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="function-syntax">InterWarehouse::create_resource</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::create_resource</span></span>:<br/><a href="2-tw.html#SP8">&#167;8</a>, <a href="2-tw.html#SP9">&#167;9</a>, <a href="2-tw.html#SP11">&#167;11</a><br/>Inter in Binary Files - <a href="3-iibf.html#SP10_1_3_1">&#167;10.1.3.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_free_resource_ID</span><span class="plain-syntax"> &gt;= </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">resources_capacity</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="2-tw.html#SP4_1" class="named-paragraph-link"><span class="named-paragraph">Double the resource list capacity</span><span class="named-paragraph-number">4.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_free_resource_ID</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">stored_resources</span><span class="plain-syntax">[</span><span class="identifier-syntax">n</span><span class="plain-syntax">].</span><span class="element-syntax">res</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL_GENERAL_POINTER</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">stored_resources</span><span class="plain-syntax">[</span><span class="identifier-syntax">n</span><span class="plain-syntax">].</span><span class="element-syntax">resource_owner</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4_1" class="paragraph-anchor"></a><b>&#167;4.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Double the resource list capacity</span><span class="named-paragraph-number">4.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">new_size</span><span class="plain-syntax"> = </span><span class="constant-syntax">128</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">new_size</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">2</span><span class="plain-syntax">*</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">resources_capacity</span><span class="plain-syntax">) </span><span class="identifier-syntax">new_size</span><span class="plain-syntax"> = </span><span class="constant-syntax">2</span><span class="plain-syntax">*</span><span class="identifier-syntax">new_size</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">INTER_MEMORY</span><span class="plain-syntax">, </span><span class="string-syntax">"Giving warehouse %d resource list of size %d (up from %d)\n"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">allocation_id</span><span class="plain-syntax">, </span><span class="identifier-syntax">new_size</span><span class="plain-syntax">, </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">resources_capacity</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">inter_warehouse_resource</span><span class="plain-syntax"> *</span><span class="identifier-syntax">storage</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">inter_warehouse_resource</span><span class="plain-syntax"> *)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Memory::calloc</span><span class="plain-syntax">((</span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">new_size</span><span class="plain-syntax">, </span><span class="reserved-syntax">sizeof</span><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse_resource</span><span class="plain-syntax">), </span><span class="constant-syntax">INTER_LINKS_MREASON</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_warehouse_resource</span><span class="plain-syntax"> *</span><span class="identifier-syntax">old</span><span class="plain-syntax"> = </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">stored_resources</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="function-syntax">&lt;warehouse-&gt;</span><span class="element-syntax">resources_capacity</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) </span><span class="identifier-syntax">storage</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">] = </span><span class="identifier-syntax">old</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">];</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">resources_capacity</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Memory::I7_free</span><span class="plain-syntax">(</span><span class="identifier-syntax">old</span><span class="plain-syntax">, </span><span class="constant-syntax">INTER_LINKS_MREASON</span><span class="plain-syntax">, (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">resources_capacity</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">stored_resources</span><span class="plain-syntax"> = </span><span class="identifier-syntax">storage</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">resources_capacity</span><span class="plain-syntax"> = </span><span class="identifier-syntax">new_size</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-tw.html#SP4">&#167;4</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>Every resource is tied to a package which owns it. This is only in fact used to
determine the tree which owns it &mdash; but we store the package, not the tree, because
when material transmigrates from one tree to another, the owning package can then
stay the same: it is just that <a href="2-pck.html#SP4" class="internal">InterPackage::tree</a> will return a different
tree after the movement has taken place.
</p>

<p class="commentary">The following conveniently loops through all valid resource IDs for a given tree:
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="identifier-syntax">LOOP_OVER_RESOURCE_IDS</span><span class="plain-syntax">(</span><span class="identifier-syntax">n</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="identifier-syntax">n</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">housed</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_free_resource_ID</span><span class="plain-syntax">; </span><span class="identifier-syntax">n</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">housed</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">stored_resources</span><span class="plain-syntax">[</span><span class="identifier-syntax">n</span><span class="plain-syntax">].</span><span class="element-syntax">resource_owner</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">            (</span><a href="2-pck.html#SP4" class="function-link"><span class="function-syntax">InterPackage::tree</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">housed</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">stored_resources</span><span class="plain-syntax">[</span><span class="identifier-syntax">n</span><span class="plain-syntax">].</span><span class="element-syntax">resource_owner</span><span class="plain-syntax">) == </span><span class="identifier-syntax">I</span><span class="plain-syntax">))</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. </b>So what can a resource be? The following types are supported, and can be
deduced by looking at what class is stored in the general pointer <span class="extract"><span class="extract-syntax">res</span></span>; this
saves redundantly storing a type field in <a href="2-tw.html#SP3" class="internal">inter_warehouse_resource</a>.
</p>

<pre class="definitions code-font"><span class="definition-keyword">enum</span> <span class="constant-syntax">TEXT_IRSRC</span><span class="plain-syntax"> </span><span class="identifier-syntax">from</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">SYMBOLS_TABLE_IRSRC</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">NODE_LIST_IRSRC</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">PACKAGE_REF_IRSRC</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="function-syntax">InterWarehouse::resource_type_code</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::resource_type_code</span></span>:<br/>Inter in Binary Files - <a href="3-iibf.html#SP10_2_3_2">&#167;10.2.3.2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">n</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">n</span><span class="plain-syntax"> &gt;= </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_free_resource_ID</span><span class="plain-syntax">)) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"bad resource ID"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">stored_resources</span><span class="plain-syntax">[</span><span class="identifier-syntax">n</span><span class="plain-syntax">].</span><span class="element-syntax">res</span><span class="plain-syntax">.</span><span class="identifier-syntax">run_time_type_code</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">text_stream_CLASS:</span><span class="plain-syntax">         </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">TEXT_IRSRC</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">inter_symbols_table_CLASS:</span><span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">SYMBOLS_TABLE_IRSRC</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">inter_node_list_CLASS:</span><span class="plain-syntax">     </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">NODE_LIST_IRSRC</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">inter_package_CLASS:</span><span class="plain-syntax">       </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">PACKAGE_REF_IRSRC</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">InterWarehouse::known_type_code</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::known_type_code</span></span>:<br/>Verifying Inter - <a href="3-vi.html#SP7">&#167;7</a>, <a href="3-vi.html#SP8">&#167;8</a>, <a href="3-vi.html#SP9">&#167;9</a>, <a href="3-vi.html#SP10">&#167;10</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">n</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">n</span><span class="plain-syntax"> &gt;= </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_free_resource_ID</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">stored_resources</span><span class="plain-syntax">[</span><span class="identifier-syntax">n</span><span class="plain-syntax">].</span><span class="element-syntax">res</span><span class="plain-syntax">.</span><span class="identifier-syntax">run_time_type_code</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">text_stream_CLASS:</span><span class="plain-syntax">         </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">TEXT_IRSRC</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">inter_symbols_table_CLASS:</span><span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">SYMBOLS_TABLE_IRSRC</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">inter_node_list_CLASS:</span><span class="plain-syntax">     </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">NODE_LIST_IRSRC</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">inter_package_CLASS:</span><span class="plain-syntax">       </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">PACKAGE_REF_IRSRC</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>First, it can be a text:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="function-syntax">InterWarehouse::create_text</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::create_text</span></span>:<br/>Annotations - <a href="2-ann.html#SP6">&#167;6</a>, <a href="2-ann.html#SP15">&#167;15</a><br/>Inter Value Pairs - <a href="3-ivp.html#SP6">&#167;6</a>, <a href="3-ivp.html#SP8">&#167;8</a>, <a href="3-ivp.html#SP9">&#167;9</a>, <a href="3-ivp.html#SP11">&#167;11</a>, <a href="3-ivp.html#SP15">&#167;15</a><br/>The Insert Construct - <a href="4-tic.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">owner</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="2-tw.html#SP11" class="function-link"><span class="function-syntax">InterWarehouse::create_ref</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">STORE_POINTER_text_stream</span><span class="plain-syntax">(</span><span class="identifier-syntax">Str::new</span><span class="plain-syntax">()), </span><span class="identifier-syntax">owner</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="function-syntax">InterWarehouse::create_text_at</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::create_text_at</span></span>:<br/>The Comment Construct - <a href="4-tcc.html#SP2">&#167;2</a><br/>The Origin Construct - <a href="4-toc.html#SP2">&#167;2</a><br/>The Pragma Construct - <a href="4-tpc4.html#SP2">&#167;2</a><br/>The Inv Construct - <a href="5-tic.html#SP3">&#167;3</a><br/>The Splat Construct - <a href="5-tsc.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_bookmark</span><span class="plain-syntax"> *</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">text</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax"> = </span><a href="2-bkm.html#SP7" class="function-link"><span class="function-syntax">InterBookmark::warehouse</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">text_ID</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP7" class="function-link"><span class="function-syntax">InterWarehouse::create_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><a href="2-bkm.html#SP6" class="function-link"><span class="function-syntax">InterBookmark::package</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">to</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP7" class="function-link"><span class="function-syntax">InterWarehouse::get_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Str::copy</span><span class="plain-syntax">(</span><span class="identifier-syntax">to</span><span class="plain-syntax">, </span><span class="identifier-syntax">text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">text_ID</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="function-syntax">InterWarehouse::get_text</span><button class="popup" onclick="togglePopup('usagePopup7')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup7">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::get_text</span></span>:<br/>Inter Nodes - <a href="2-in.html#SP14">&#167;14</a><br/>Annotations - <a href="2-ann.html#SP6">&#167;6</a>, <a href="2-ann.html#SP7">&#167;7</a>, <a href="2-ann.html#SP15">&#167;15</a><br/>Inter in Binary Files - <a href="3-iibf.html#SP10_2_3_2_1">&#167;10.2.3.2.1</a><br/>Inter Value Pairs - <a href="3-ivp.html#SP6">&#167;6</a>, <a href="3-ivp.html#SP8">&#167;8</a>, <a href="3-ivp.html#SP9">&#167;9</a>, <a href="3-ivp.html#SP11">&#167;11</a>, <a href="3-ivp.html#SP15">&#167;15</a><br/>The Insert Construct - <a href="4-tic.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">gp</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP11" class="function-link"><span class="function-syntax">InterWarehouse::get_ref</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">n</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gp</span><span class="plain-syntax">.</span><span class="identifier-syntax">run_time_type_code</span><span class="plain-syntax"> != </span><span class="identifier-syntax">text_stream_CLASS</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">RETRIEVE_POINTER_text_stream</span><span class="plain-syntax">(</span><span class="identifier-syntax">gp</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. </b>Second, a symbols table. Uniquely, this one does not specify an owning package
when the resource is created: that's because a package can only be made when a
symbols table for it already exists, so we need the table first. The owner is
therefore initially not set, and must be explicitly set after the package has
been created, using <a href="2-tw.html#SP8" class="internal">InterWarehouse::set_symbols_table_owner</a>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="function-syntax">InterWarehouse::create_symbols_table</span><button class="popup" onclick="togglePopup('usagePopup8')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup8">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::create_symbols_table</span></span>:<br/>Inter Trees - <a href="2-it.html#SP2_1">&#167;2.1</a><br/>The Package Construct - <a href="4-tpc.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP4" class="function-link"><span class="function-syntax">InterWarehouse::create_resource</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_symbols_table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">new_table</span><span class="plain-syntax"> = </span><a href="2-st.html#SP2" class="function-link"><span class="function-syntax">InterSymbolsTable::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">n</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="2-tw.html#SP11" class="function-link"><span class="function-syntax">InterWarehouse::create_ref_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">n</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">STORE_POINTER_inter_symbols_table</span><span class="plain-syntax">(</span><span class="identifier-syntax">new_table</span><span class="plain-syntax">), </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">InterWarehouse::set_symbols_table_owner</span><button class="popup" onclick="togglePopup('usagePopup9')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup9">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::set_symbols_table_owner</span></span>:<br/>Inter Trees - <a href="2-it.html#SP2_1">&#167;2.1</a><br/>The Package Construct - <a href="4-tpc.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">owner</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-tw.html#SP8" class="function-link"><span class="function-syntax">InterWarehouse::get_symbols_table</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">n</span><span class="plain-syntax">) == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"not a symbols table"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">stored_resources</span><span class="plain-syntax">[</span><span class="identifier-syntax">n</span><span class="plain-syntax">].</span><span class="element-syntax">resource_owner</span><span class="plain-syntax"> = </span><span class="identifier-syntax">owner</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">inter_symbols_table</span><span class="plain-syntax"> *</span><span class="function-syntax">InterWarehouse::get_symbols_table</span><button class="popup" onclick="togglePopup('usagePopup10')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup10">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::get_symbols_table</span></span>:<br/>Inter Trees - <a href="2-it.html#SP2_1">&#167;2.1</a><br/>Inter Nodes - <a href="2-in.html#SP14">&#167;14</a><br/>Inter in Binary Files - <a href="3-iibf.html#SP10_1_3_2_2">&#167;10.1.3.2.2</a>, <a href="3-iibf.html#SP10_2_3_2_2">&#167;10.2.3.2.2</a>, <a href="3-iibf.html#SP10_1_3_2_3">&#167;10.1.3.2.3</a>, <a href="3-iibf.html#SP10_1_4">&#167;10.1.4</a>, <a href="3-iibf.html#SP10_2_4">&#167;10.2.4</a><br/>The Package Construct - <a href="4-tpc.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">gp</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP11" class="function-link"><span class="function-syntax">InterWarehouse::get_ref</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">n</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gp</span><span class="plain-syntax">.</span><span class="identifier-syntax">run_time_type_code</span><span class="plain-syntax"> != </span><span class="constant-syntax">inter_symbols_table_CLASS</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">RETRIEVE_POINTER_inter_symbols_table</span><span class="plain-syntax">(</span><span class="identifier-syntax">gp</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. </b>Third, a resource can be a package &mdash; or, really, a pointer to a package, a
form of resource which allows bytecode to contain cross-references to packages.
</p>

<p class="commentary">This may as well be its own owner, since it can be valid only if the package
pointed to is in the same tree as the bytecode instruction using the resource.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="function-syntax">InterWarehouse::create_package</span><button class="popup" onclick="togglePopup('usagePopup11')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup11">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::create_package</span></span>:<br/>Inter Trees - <a href="2-it.html#SP2_1">&#167;2.1</a><br/>The Package Construct - <a href="4-tpc.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP4" class="function-link"><span class="function-syntax">InterWarehouse::create_resource</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">new_pack</span><span class="plain-syntax"> = </span><a href="2-pck.html#SP3" class="function-link"><span class="function-syntax">InterPackage::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">n</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="2-tw.html#SP11" class="function-link"><span class="function-syntax">InterWarehouse::create_ref_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">n</span><span class="plain-syntax">, </span><span class="identifier-syntax">STORE_POINTER_inter_package</span><span class="plain-syntax">(</span><span class="identifier-syntax">new_pack</span><span class="plain-syntax">),</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">new_pack</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="function-syntax">InterWarehouse::get_package</span><button class="popup" onclick="togglePopup('usagePopup12')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup12">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::get_package</span></span>:<br/>Inter Trees - <a href="2-it.html#SP2_1">&#167;2.1</a><br/>Inter Nodes - <a href="2-in.html#SP14">&#167;14</a><br/>Inter in Binary Files - <a href="3-iibf.html#SP10_1_3_2_3">&#167;10.1.3.2.3</a>, <a href="3-iibf.html#SP10_2_3_2_3">&#167;10.2.3.2.3</a>, <a href="3-iibf.html#SP10_1_5_1">&#167;10.1.5.1</a><br/>The Package Construct - <a href="4-tpc.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">gp</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP11" class="function-link"><span class="function-syntax">InterWarehouse::get_ref</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">n</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gp</span><span class="plain-syntax">.</span><span class="identifier-syntax">run_time_type_code</span><span class="plain-syntax"> != </span><span class="constant-syntax">inter_package_CLASS</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">RETRIEVE_POINTER_inter_package</span><span class="plain-syntax">(</span><span class="identifier-syntax">gp</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. </b>Finally, a node list.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="function-syntax">InterWarehouse::create_node_list</span><button class="popup" onclick="togglePopup('usagePopup13')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup13">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::create_node_list</span></span>:<br/>The Instance Construct - <a href="4-tic2.html#SP2">&#167;2</a><br/>The Property Construct - <a href="4-tpc6.html#SP2">&#167;2</a><br/>The Typename Construct - <a href="4-ttc.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">owner</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="2-tw.html#SP11" class="function-link"><span class="function-syntax">InterWarehouse::create_ref</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">STORE_POINTER_inter_node_list</span><span class="plain-syntax">(</span><a href="2-inl.html#SP1" class="function-link"><span class="function-syntax">InterNodeList::new</span></a><span class="plain-syntax">()), </span><span class="identifier-syntax">owner</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">inter_node_list</span><span class="plain-syntax"> *</span><span class="function-syntax">InterWarehouse::get_node_list</span><button class="popup" onclick="togglePopup('usagePopup14')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup14">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::get_node_list</span></span>:<br/>Inter Nodes - <a href="2-in.html#SP14">&#167;14</a><br/>Inter in Binary Files - <a href="3-iibf.html#SP10_1_3_2_4">&#167;10.1.3.2.4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">gp</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP11" class="function-link"><span class="function-syntax">InterWarehouse::get_ref</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">n</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gp</span><span class="plain-syntax">.</span><span class="identifier-syntax">run_time_type_code</span><span class="plain-syntax"> != </span><span class="constant-syntax">inter_node_list_CLASS</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">RETRIEVE_POINTER_inter_node_list</span><span class="plain-syntax">(</span><span class="identifier-syntax">gp</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. </b>All of which use the following:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="function-syntax">InterWarehouse::get_ref</span><button class="popup" onclick="togglePopup('usagePopup15')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup15">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::get_ref</span></span>:<br/><a href="2-tw.html#SP7">&#167;7</a>, <a href="2-tw.html#SP8">&#167;8</a>, <a href="2-tw.html#SP9">&#167;9</a>, <a href="2-tw.html#SP10">&#167;10</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">n</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">n</span><span class="plain-syntax"> &gt;= </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_free_resource_ID</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL_GENERAL_POINTER</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">stored_resources</span><span class="plain-syntax">[</span><span class="identifier-syntax">n</span><span class="plain-syntax">].</span><span class="element-syntax">res</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="function-syntax">InterWarehouse::create_ref</span><button class="popup" onclick="togglePopup('usagePopup16')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup16">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::create_ref</span></span>:<br/><a href="2-tw.html#SP7">&#167;7</a>, <a href="2-tw.html#SP10">&#167;10</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">ref</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">owner</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP4" class="function-link"><span class="function-syntax">InterWarehouse::create_resource</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="2-tw.html#SP11" class="function-link"><span class="function-syntax">InterWarehouse::create_ref_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">n</span><span class="plain-syntax">, </span><span class="identifier-syntax">ref</span><span class="plain-syntax">, </span><span class="identifier-syntax">owner</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="function-syntax">InterWarehouse::create_ref_at</span><button class="popup" onclick="togglePopup('usagePopup17')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup17">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::create_ref_at</span></span>:<br/><a href="2-tw.html#SP8">&#167;8</a>, <a href="2-tw.html#SP9">&#167;9</a><br/>Inter in Binary Files - <a href="3-iibf.html#SP10_1_3_2_1">&#167;10.1.3.2.1</a>, <a href="3-iibf.html#SP10_1_3_2_2">&#167;10.1.3.2.2</a>, <a href="3-iibf.html#SP10_1_3_2_3">&#167;10.1.3.2.3</a>, <a href="3-iibf.html#SP10_1_3_2_4">&#167;10.1.3.2.4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">ref</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">owner</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">stored_resources</span><span class="plain-syntax">[</span><span class="identifier-syntax">n</span><span class="plain-syntax">].</span><span class="element-syntax">res</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ref</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">stored_resources</span><span class="plain-syntax">[</span><span class="identifier-syntax">n</span><span class="plain-syntax">].</span><span class="element-syntax">resource_owner</span><span class="plain-syntax"> = </span><span class="identifier-syntax">owner</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. The bytecode storage.</b>Conceptually, a warehouse stores bytecode at (word) addresses which begin from 0.
Each instruction occupies a contiguous run of addresses. That all sounds like
a typical machine-code arrangement, but:
</p>

<ul class="items"><li>(a) the instructions themselves contain neither absolute addresses nor address
offsets &mdash; they are oblivious to where they are stored, and refer to code
positions using labels instead;
</li><li>(b) some storage may remain unused, and the addresses of instructions do not
correspond to their order in the code.
</li></ul>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">inter_warehouse_room</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">owning_warehouse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">room_usage</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">room_capacity</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> *</span><span class="identifier-syntax">bytecode</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">inter_warehouse_room</span><span class="plain-syntax"> *</span><span class="identifier-syntax">next_room</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">inter_warehouse_room</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure inter_warehouse_room is accessed in 2/in and here.</li></ul>
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. </b>The warehouse is divided into a series of rooms of steadily telescoping sizes.
Unless an improbably large demand is made for a very long single instruction,
they will typically look like:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">room</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">      </span><span class="identifier-syntax">addresses</span><span class="plain-syntax"> </span><span class="constant-syntax">0x000000</span><span class="plain-syntax"> </span><span class="identifier-syntax">to</span><span class="plain-syntax"> </span><span class="constant-syntax">0x000fff</span><span class="plain-syntax"> (4</span><span class="identifier-syntax">K</span><span class="plain-syntax"> </span><span class="identifier-syntax">words</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">room</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">      </span><span class="identifier-syntax">addresses</span><span class="plain-syntax"> </span><span class="constant-syntax">0x001000</span><span class="plain-syntax"> </span><span class="identifier-syntax">to</span><span class="plain-syntax"> </span><span class="constant-syntax">0x002fff</span><span class="plain-syntax"> (8</span><span class="identifier-syntax">K</span><span class="plain-syntax"> </span><span class="identifier-syntax">words</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">room</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span><span class="plain-syntax">      </span><span class="identifier-syntax">addresses</span><span class="plain-syntax"> </span><span class="constant-syntax">0x003000</span><span class="plain-syntax"> </span><span class="identifier-syntax">to</span><span class="plain-syntax"> </span><span class="constant-syntax">0x006fff</span><span class="plain-syntax"> (16</span><span class="identifier-syntax">K</span><span class="plain-syntax"> </span><span class="identifier-syntax">words</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">room</span><span class="plain-syntax"> </span><span class="constant-syntax">3</span><span class="plain-syntax">      </span><span class="identifier-syntax">addresses</span><span class="plain-syntax"> </span><span class="constant-syntax">0x007000</span><span class="plain-syntax"> </span><span class="identifier-syntax">to</span><span class="plain-syntax"> </span><span class="constant-syntax">0x00efff</span><span class="plain-syntax"> (32</span><span class="identifier-syntax">K</span><span class="plain-syntax"> </span><span class="identifier-syntax">words</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    ...</span>
</pre>
<p class="commentary">though probably not with boundaries as neat as that, since there will be a
few words of unused space at the end of each room.
</p>

<p class="commentary">In a typical <a href="../inform7/index.html" class="internal">inform7</a> run, we reach about the 9th room, so that the address
space amounts to around 2 million words.
</p>

<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>&#167;14. </b>A single instruction will occupy a contiguous run of addresses, and will
consist of a preframe (always <span class="extract"><span class="extract-syntax">PREFRAME_SIZE</span></span> words) and then a frame (of
a variable size, though always at least 2 words). This will always lie
inside a single room: this is why, if we ask for an instruction with a
50000-word frame, we would force larger rooms to be created.
</p>

<p class="commentary">The following represents where an instruction is stored. The address of the
preframe will be <span class="extract"><span class="extract-syntax">index</span></span> plus the sum of <span class="extract"><span class="extract-syntax">room_usage</span></span> for previous rooms; the address
of the frame will be <span class="extract"><span class="extract-syntax">PREFRAME_SIZE</span></span> more than that, since the frame always
immediately follows the preframe. <span class="extract"><span class="extract-syntax">instruction</span></span> points to the first word of
the frame, and the <span class="extract"><span class="extract-syntax">extent</span></span> is the size of the frame, so the size of the whole
instruction is <span class="extract"><span class="extract-syntax">extent + PREFRAME_SIZE</span></span>.
</p>

<p class="commentary">Note that <span class="extract"><span class="extract-syntax">instruction</span></span> and <span class="extract"><span class="extract-syntax">extent</span></span> are both in principle redundant in this
structure. If you know <span class="extract"><span class="extract-syntax">in_room</span></span> and <span class="extract"><span class="extract-syntax">index</span></span> you know everything, because:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax"> == </span><span class="identifier-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">in_room</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">bytecode</span><span class="plain-syntax"> + </span><span class="identifier-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">index</span><span class="plain-syntax"> + </span><span class="constant-syntax">PREFRAME_SIZE</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">extent</span><span class="plain-syntax"> == </span><span class="identifier-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">in_room</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">bytecode</span><span class="plain-syntax">[</span><span class="identifier-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">index</span><span class="plain-syntax"> + </span><span class="constant-syntax">PREFRAME_SKIP_AMOUNT</span><span class="plain-syntax">] - </span><span class="constant-syntax">PREFRAME_SIZE</span>
</pre>
<p class="commentary">But speed of access is so important that we store these two fields redundantly
in order to cache the results of those two calculations.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">warehouse_floor_space</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">inter_warehouse_room</span><span class="plain-syntax"> *</span><span class="identifier-syntax">in_room</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">index</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> *</span><span class="identifier-syntax">instruction</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">extent</span><span class="plain-syntax">;</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">warehouse_floor_space</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure warehouse_floor_space is accessed in 2/in, 2/bkm, 2/st, 2/ann, 2/trn, 3/ic, 3/iibf, 3/iitf, 3/vi, 3/ivp, 3/idt, 4/tcc, 4/tcc2, 4/tic, 4/tic2, 4/toc, 4/tpc, 4/tpc3, 4/tpc4, 4/tpc5, 4/tpc6, 4/tpc8, 4/ttc, 5/tac, 5/tcc, 5/tcc2, 5/tec, 5/tic, 5/trc2, 5/tsc and here.</li></ul>
<p class="commentary firstcommentary"><a id="SP15" class="paragraph-anchor"></a><b>&#167;15. </b>We provide an API of just two functions to handle all this. Firstly,
<a href="2-tw.html#SP15" class="internal">InterWarehouse::make_floor_space</a> makes room for an instruction of <span class="extract"><span class="extract-syntax">n</span></span> words.
(This is the frame extent, and does not include the <span class="extract"><span class="extract-syntax">PREFRAME_SIZE</span></span>.)
</p>

<p class="commentary">Note that this function always succeeds, because an internal error is thrown
if the system is out of memory.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">warehouse_floor_space</span><span class="plain-syntax"> </span><span class="function-syntax">InterWarehouse::make_floor_space</span><button class="popup" onclick="togglePopup('usagePopup18')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup18">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::make_floor_space</span></span>:<br/><a href="2-tw.html#SP16_2">&#167;16.2</a><br/>Inter Nodes - <a href="2-in.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">total_extent</span><span class="plain-syntax"> = </span><span class="identifier-syntax">n</span><span class="plain-syntax"> + </span><span class="constant-syntax">PREFRAME_SIZE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="2-tw.html#SP15_1" class="named-paragraph-link"><span class="named-paragraph">Make a new and bigger room if necessary</span><span class="named-paragraph-number">15.1</span></a></span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">inter_warehouse_room</span><span class="plain-syntax"> *</span><span class="identifier-syntax">IS</span><span class="plain-syntax"> = </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">last_room</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">at</span><span class="plain-syntax"> = </span><span class="identifier-syntax">IS</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">room_usage</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">total_extent</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) </span><span class="identifier-syntax">IS</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">bytecode</span><span class="plain-syntax">[</span><span class="identifier-syntax">at</span><span class="plain-syntax"> + </span><span class="identifier-syntax">i</span><span class="plain-syntax">] = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">IS</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">bytecode</span><span class="plain-syntax">[</span><span class="identifier-syntax">at</span><span class="plain-syntax"> + </span><span class="constant-syntax">PREFRAME_SKIP_AMOUNT</span><span class="plain-syntax">] = (</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">total_extent</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">IS</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">room_usage</span><span class="plain-syntax"> += </span><span class="identifier-syntax">total_extent</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">warehouse_floor_space</span><span class="plain-syntax"> </span><span class="identifier-syntax">W</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">in_room</span><span class="plain-syntax"> = </span><span class="identifier-syntax">IS</span><span class="plain-syntax">; </span><span class="identifier-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">index</span><span class="plain-syntax"> = </span><span class="identifier-syntax">at</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">IS</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">at</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">at</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">IS</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">room_usage</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax"> = &amp;(</span><span class="identifier-syntax">IS</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">bytecode</span><span class="plain-syntax">[</span><span class="identifier-syntax">at</span><span class="plain-syntax"> + </span><span class="constant-syntax">PREFRAME_SIZE</span><span class="plain-syntax">]);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">extent</span><span class="plain-syntax"> = ((</span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">IS</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">bytecode</span><span class="plain-syntax">[</span><span class="identifier-syntax">at</span><span class="plain-syntax"> + </span><span class="constant-syntax">PREFRAME_SKIP_AMOUNT</span><span class="plain-syntax">]) - </span><span class="constant-syntax">PREFRAME_SIZE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">; </span><span class="identifier-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">extent</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">W</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP15_1" class="paragraph-anchor"></a><b>&#167;15.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Make a new and bigger room if necessary</span><span class="named-paragraph-number">15.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_warehouse_room</span><span class="plain-syntax"> *</span><span class="identifier-syntax">IS</span><span class="plain-syntax"> = </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">last_room</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">IS</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">IS</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">room_usage</span><span class="plain-syntax"> + </span><span class="identifier-syntax">total_extent</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">IS</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">room_capacity</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">IS</span><span class="plain-syntax">) </span><span class="identifier-syntax">IS</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">room_capacity</span><span class="plain-syntax"> = </span><span class="identifier-syntax">IS</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">room_usage</span><span class="plain-syntax">;</span>

<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">new_capacity</span><span class="plain-syntax"> = </span><span class="constant-syntax">4096</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">IS</span><span class="plain-syntax">) </span><span class="identifier-syntax">new_capacity</span><span class="plain-syntax"> = </span><span class="constant-syntax">2</span><span class="plain-syntax">*</span><span class="identifier-syntax">IS</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">room_capacity</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">total_extent</span><span class="plain-syntax"> &gt;= </span><span class="identifier-syntax">new_capacity</span><span class="plain-syntax">) </span><span class="identifier-syntax">new_capacity</span><span class="plain-syntax"> = </span><span class="constant-syntax">2</span><span class="plain-syntax">*</span><span class="identifier-syntax">new_capacity</span><span class="plain-syntax">;</span>

<span class="plain-syntax">        </span><span class="reserved-syntax">inter_warehouse_room</span><span class="plain-syntax"> *</span><span class="identifier-syntax">new_room</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">inter_warehouse_room</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">new_room</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">owning_warehouse</span><span class="plain-syntax"> = </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">new_room</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">room_usage</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">new_room</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">room_capacity</span><span class="plain-syntax"> = </span><span class="identifier-syntax">new_capacity</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">new_room</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">bytecode</span><span class="plain-syntax"> = (</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> *)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Memory::calloc</span><span class="plain-syntax">(</span><span class="identifier-syntax">new_capacity</span><span class="plain-syntax">, </span><span class="reserved-syntax">sizeof</span><span class="plain-syntax">(</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax">), </span><span class="constant-syntax">INTER_BYTECODE_MREASON</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">INTER_MEMORY</span><span class="plain-syntax">, </span><span class="string-syntax">"Created warehouse room %d with capacity %08x\n"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">new_room</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">allocation_id</span><span class="plain-syntax">, </span><span class="identifier-syntax">new_room</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">room_capacity</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">IS</span><span class="plain-syntax">) </span><span class="identifier-syntax">IS</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_room</span><span class="plain-syntax"> = </span><span class="identifier-syntax">new_room</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">first_room</span><span class="plain-syntax"> = </span><span class="identifier-syntax">new_room</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">last_room</span><span class="plain-syntax"> = </span><span class="identifier-syntax">new_room</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-tw.html#SP15">&#167;15</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP16" class="paragraph-anchor"></a><b>&#167;16. </b>Secondly, <a href="2-tw.html#SP16" class="internal">InterWarehouse::enlarge_floor_space</a> adds extra length to an
existing instruction &mdash; which may involve moving its bytecode to a bigger room,
in the worst case, but is more typically very fast. Note that this function
may only be called on the floor space for the most-recently creates instruction,
so the floor space is guaranteed to be at the end of the space used in the
current room.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">by</span></span> cannot be negative (it is unsigned). The instruction therefore always
extends, not contracts. The values of the new words added are undefined:
they will very likely be 0 but do not rely upon this.
</p>

<p class="commentary">Note that this function always succeeds, because an internal error is thrown
if the system is out of memory.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">warehouse_floor_space</span><span class="plain-syntax"> </span><span class="function-syntax">InterWarehouse::enlarge_floor_space</span><button class="popup" onclick="togglePopup('usagePopup19')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup19">Usage of <span class="code-font"><span class="function-syntax">InterWarehouse::enlarge_floor_space</span></span>:<br/>Inter Nodes - <a href="2-in.html#SP12">&#167;12</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">warehouse_floor_space</span><span class="plain-syntax"> </span><span class="identifier-syntax">FW</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">by</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="comment-syntax"> Have we already moved on to building further instructions?</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">FW</span><span class="plain-syntax">.</span><span class="element-syntax">in_room</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_room</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"too late to extend instruction"</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">FW</span><span class="plain-syntax">.</span><span class="element-syntax">in_room</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">room_usage</span><span class="plain-syntax"> + (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">by</span><span class="plain-syntax"> &lt;= </span><span class="identifier-syntax">FW</span><span class="plain-syntax">.</span><span class="element-syntax">in_room</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">room_capacity</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="2-tw.html#SP16_1" class="named-paragraph-link"><span class="named-paragraph">The existing room already has sufficient capacity to accommodate the extra</span><span class="named-paragraph-number">16.1</span></a></span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="2-tw.html#SP16_2" class="named-paragraph-link"><span class="named-paragraph">The existing room is not big enough</span><span class="named-paragraph-number">16.2</span></a></span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FW</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP16_1" class="paragraph-anchor"></a><b>&#167;16.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">The existing room already has sufficient capacity to accommodate the extra</span><span class="named-paragraph-number">16.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">FW</span><span class="plain-syntax">.</span><span class="element-syntax">in_room</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">bytecode</span><span class="plain-syntax">[</span><span class="identifier-syntax">FW</span><span class="plain-syntax">.</span><span class="element-syntax">index</span><span class="plain-syntax"> + </span><span class="constant-syntax">PREFRAME_SKIP_AMOUNT</span><span class="plain-syntax">] += </span><span class="identifier-syntax">by</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">FW</span><span class="plain-syntax">.</span><span class="element-syntax">in_room</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">room_usage</span><span class="plain-syntax"> += </span><span class="identifier-syntax">by</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">FW</span><span class="plain-syntax">.</span><span class="element-syntax">extent</span><span class="plain-syntax"> += </span><span class="identifier-syntax">by</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-tw.html#SP16">&#167;16</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP16_2" class="paragraph-anchor"></a><b>&#167;16.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">The existing room is not big enough</span><span class="named-paragraph-number">16.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">warehouse_floor_space</span><span class="plain-syntax"> </span><span class="identifier-syntax">new_W</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">        </span><a href="2-tw.html#SP15" class="function-link"><span class="function-syntax">InterWarehouse::make_floor_space</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">FW</span><span class="plain-syntax">.</span><span class="element-syntax">in_room</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">owning_warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">FW</span><span class="plain-syntax">.</span><span class="element-syntax">extent</span><span class="plain-syntax"> + (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">by</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">FW</span><span class="plain-syntax">.</span><span class="element-syntax">in_room</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">room_usage</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FW</span><span class="plain-syntax">.</span><span class="element-syntax">index</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">FW</span><span class="plain-syntax">.</span><span class="element-syntax">in_room</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">room_capacity</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FW</span><span class="plain-syntax">.</span><span class="element-syntax">index</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="2-tw.html#SP16_2_1" class="named-paragraph-link"><span class="named-paragraph">Copy the bytecode for the preframe and frame to its new home</span><span class="named-paragraph-number">16.2.1</span></a></span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-tw.html#SP16">&#167;16</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP16_2_1" class="paragraph-anchor"></a><b>&#167;16.2.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Copy the bytecode for the preframe and frame to its new home</span><span class="named-paragraph-number">16.2.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="constant-syntax">PREFRAME_SIZE</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax"> != </span><span class="constant-syntax">PREFRAME_SKIP_AMOUNT</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">new_W</span><span class="plain-syntax">.</span><span class="element-syntax">in_room</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">bytecode</span><span class="plain-syntax">[</span><span class="identifier-syntax">new_W</span><span class="plain-syntax">.</span><span class="element-syntax">index</span><span class="plain-syntax"> + </span><span class="identifier-syntax">i</span><span class="plain-syntax">] = </span><span class="identifier-syntax">FW</span><span class="plain-syntax">.</span><span class="element-syntax">in_room</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">bytecode</span><span class="plain-syntax">[</span><span class="identifier-syntax">FW</span><span class="plain-syntax">.</span><span class="element-syntax">index</span><span class="plain-syntax"> + </span><span class="identifier-syntax">i</span><span class="plain-syntax">];</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">new_W</span><span class="plain-syntax">.</span><span class="element-syntax">extent</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">FW</span><span class="plain-syntax">.</span><span class="element-syntax">extent</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">new_W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">] = </span><span class="identifier-syntax">FW</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">];</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">new_W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">] = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">FW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">new_W</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-tw.html#SP16_2">&#167;16.2</a>.</li></ul>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="2-np.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-bm.html">1</a></li><li class="progresscurrentchapter">2</li><li class="progresssection"><a href="2-it.html">it</a></li><li class="progresssection"><a href="2-in.html">in</a></li><li class="progresssection"><a href="2-bkm.html">bkm</a></li><li class="progresssection"><a href="2-np.html">np</a></li><li class="progresscurrent">tw</li><li class="progresssection"><a href="2-pck.html">pck</a></li><li class="progresssection"><a href="2-inl.html">inl</a></li><li class="progresssection"><a href="2-st.html">st</a></li><li class="progresssection"><a href="2-sym.html">sym</a></li><li class="progresssection"><a href="2-ann.html">ann</a></li><li class="progresssection"><a href="2-tw2.html">tw2</a></li><li class="progresssection"><a href="2-trn.html">trn</a></li><li class="progresschapter"><a href="3-ic.html">3</a></li><li class="progresschapter"><a href="4-tcc.html">4</a></li><li class="progresschapter"><a href="5-tac.html">5</a></li><li class="progresschapter"><a href="6-tpc.html">6</a></li><li class="progressnext"><a href="2-pck.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

